import cv2
import numpy as np
import time
import math
def distinct(a,b):
    return math.sqrt((a[0]-b[0])**2+(a[1]-b[1])**2)
def map():
    width=800
    height=800
    r=5
    COVID_Person=1   #患covid的初始人数
    NOCOVID_Person=500   #没有covid的初始人数
    #初始化患有covid人的初始坐标
    x_COVID=np.random.randint(0,width,size=COVID_Person)
    y_COVID=np.random.randint(0,height,size=COVID_Person)

    #初始化没有患有covid人的初始坐标
    x_NOCOVID=np.random.randint(0,width,size=NOCOVID_Person)
    y_NOCOVID=np.random.randint(0,height,size=NOCOVID_Person)


    while(cv2.waitKey(1)==-1):
        temp = np.zeros(NOCOVID_Person)
        for i in range(NOCOVID_Person):
            for j in range(COVID_Person):
                if distinct([x_NOCOVID[i],y_NOCOVID[i]],[x_COVID[j],y_COVID[j]])<=10:
                    temp[i]=1
        num=0
        for i in range(NOCOVID_Person):
            if temp[i]==1:
                x_COVID=np.append(x_COVID,x_NOCOVID[i])
                y_COVID=np.append(y_COVID,y_NOCOVID[i])
                x_NOCOVID=np.delete(x_NOCOVID,i)
                y_NOCOVID = np.delete(y_NOCOVID, i)
                num+=1
        NOCOVID_Person-=num
        COVID_Person+=num
        x_COVID+=np.random.randint(-10,10,COVID_Person)
        y_COVID += np.random.randint(-10, 10, COVID_Person)
        x_NOCOVID += np.random.randint(-10, 10, NOCOVID_Person)
        y_NOCOVID += np.random.randint(-10, 10, NOCOVID_Person)
        img = np.ones((width, height, 3), np.uint8) * 255
        for i in range(COVID_Person):
            img=cv2.circle(img,(x_COVID[i],y_COVID[i]),r,(255,0,0),-1)
        for i in range(NOCOVID_Person):
            img=cv2.circle(img,(x_NOCOVID[i],y_NOCOVID[i]),r,(0,255,0),-1)
        cv2.imshow('COVID_MAP',img)
        time.sleep(1)
    cv2.destroyAllWindows()
map()